# -*- coding: utf-8 -*-
# @Time    : 2023/9/19 15:10
# @Author  : chenyinhua
# @File    : test_create_export_and_delete_project.py
# @Software: PyCharm
# @Desc:

# 标准库导入
# 第三方库导入
import allure
# 本地应用/模块导入
from utils.ui_utils.base_page import BasePage


class CreateExportProjectPage(BasePage):

    @allure.step("输入项目名称: {name}")
    def input_project_name(self, name):
        """
        输入项目名称
        """
        # 输入项目名称
        self.input(locator="xpath=//input[@id='NewWorkForm_name']", text=name)

    @allure.step("输入项目标识: {identifier}")
    def input_project_identifier(self, identifier):
        """
        输入项目标识
        """

        # 输入项目标识
        self.input(locator="xpath=//input[@id='NewWorkForm_repository_name']", text=identifier)

    @allure.step("输入项目简介: {desc}")
    def input_project_desc(self, desc):
        """
        输入项目简介
        """

        # 输入项目简介
        self.input(locator="xpath=//textarea[@id='NewWorkForm_description']", text=desc)

    @allure.step("选择.gitignore: {gitignore}")
    def choose_project_gitignore(self, gitignore):
        """
        选择.gitignore
        """
        # 选择gitignore
        self.click(locator="xpath=//input[@id='NewWorkForm_ignoreFlag']")
        self.click(locator="xpath=//div[@id='NewWorkForm_ignore']")
        self.click(locator=f"//li[text()='{gitignore}']")

    @allure.step("选择开源许可证: {certificate}")
    def choose_project_licence(self, certificate):
        """
        选择开源许可证
        """

        # 选择开源许可证
        self.click(locator="xpath=//input[@id='NewWorkForm_licenseFlag']")
        self.click(locator="xpath=//div[contains(text(), '请选择开源许可证')]")
        self.click(locator=f"//li[text()='{certificate}']")

    @allure.step("选择项目类别: {category}")
    def choose_project_category(self, category):
        """
        选择项目类别
        """
        self.click(locator="xpath=//input[@id='NewWorkForm_categoreFlag']")
        self.click(locator="xpath=//div[text()='请选择项目类别']")
        self.click(locator=f"//li[text()='{category}']")

    @allure.step("选择项目语言: {language}")
    def choose_project_language(self, language):
        """
        选择项目语言
        """

        self.click(locator="xpath=//input[@id='NewWorkForm_languageFlag']")
        self.click(locator="xpath=//div[text()='请选择项目语言']")
        self.click(locator=f"//li[text()='{language}']")

    @allure.step("勾选复选框，将项目设为私有")
    def check_private_checkbox(self):
        """
        勾选复选框，将项目设为私有
        """
        # 通过id定位使用#   通过css定位使用.
        self.check(locator="#NewWorkForm_private")

    @allure.step("点击【创建项目】按钮，提交新建项目表单")
    def submit_create_project(self):
        """
        点击：创建项目 按钮，提交新建项目表单
        """
        self.click(locator="xpath=//span[text()='创建项目']/parent::button")
        self.page.wait_for_timeout(10000)  # 超时时间是10s

    def create_private_project(self, name, identifier, desc, gitignore, licence, category, language):
        """
        新建项目：
        输入项目名称，项目标识，项目简介，选择.gitignore， 开源许可证，勾选私有项目，项目语言，项目类别，点击"创建项目"按钮
        """
        self.input_project_name(name)
        self.input_project_identifier(identifier)
        self.input_project_desc(desc)
        self.choose_project_gitignore(gitignore)
        self.choose_project_licence(licence)
        self.check_private_checkbox()
        self.choose_project_category(category)
        # 往下滑动
        js = "window.scrollTo(0, 200)"
        self.page.evaluate(js)
        self.choose_project_language(language)
        self.submit_create_project()
